package com.xl6667.config;

import com.xl6667.filter.SmsCodeAuthenticationProvider;
import com.xl6667.service.impl.SmsDetailsServiceImpl;
import com.xl6667.util.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

@Component
public class SmsCodeAuthenticationSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
    @Autowired
    private SmsDetailsServiceImpl smsDetailsServiceImpl;
    @Autowired
    private RedisCache redisCache;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        SmsCodeAuthenticationProvider smsCodeAuthenticationProvider = new SmsCodeAuthenticationProvider();
        smsCodeAuthenticationProvider.setUserDetailsService(smsDetailsServiceImpl);
        smsCodeAuthenticationProvider.setRedisCache(redisCache);

        //添加smsProvider
        http.authenticationProvider(smsCodeAuthenticationProvider);
    }
}
